﻿package com.webdesign.action;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.webdesign.dto.HomeworkInfoDTO;
import com.webdesign.service.ITbHomeworkService;

@Controller("AssignHomeworkAction")
@Scope("prototype")
public class AssignHomeworkAction extends ActionSupport{
	private static final String REDIRECT="redirect";
	private ITbHomeworkService iTbHomeworkService;
	private String title;
	private String description;
	private String starttime;
	private String endtime;
	private String graded;
	
	
	
	/*
	 * 发布作业页面
	 */
	public String assignHomework(){
		return "success";
	}
	
	/*
	 * 教师发布一次作业，发布成功跳转到教师主页，显示出当前学年所有作业，包括刚发布的作业
	 */
	public String submitHomework(){
		Map<String, Object> session = ActionContext.getContext().getSession();
		String termid = (String)session.get("termid");
		String userid = (String)session.get("userid");
		Boolean flag = iTbHomeworkService.submitHomework(title, description, starttime, endtime, graded, termid,userid);
		if(flag == true){
			ActionContext.getContext().put("url", "/teacher/showTermAndHomework");
			return REDIRECT;
		}else{
			return "error";
		}
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getStarttime() {
		return starttime;
	}

	public void setStarttime(String starttime) {
		this.starttime = starttime;
	}

	public String getEndtime() {
		return endtime;
	}

	public void setEndtime(String endtime) {
		this.endtime = endtime;
	}

	public String getGraded() {
		return graded;
	}

	public void setGraded(String graded) {
		this.graded = graded;
	}

	public ITbHomeworkService getiTbHomeworkService() {
		return iTbHomeworkService;
	}

	@Resource(name="TbHomeworkService")
	public void setiTbHomeworkService(ITbHomeworkService iTbHomeworkService) {
		this.iTbHomeworkService = iTbHomeworkService;
	}

	
	
	
}
